package com.flydog.mall.controller.pms;

import com.flydog.mall.common.api.CommonResult;
import com.flydog.mall.common.api.PageResponse;
import com.flydog.mall.dto.PmsProductCategoryEntityParam;
import com.flydog.mall.dto.PmsProductCategoryParam;
import com.flydog.mall.entity.pms.PmsProductCategory;
import com.flydog.mall.service.pms.PmsProductCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Cao
 * @description 商品分类控制
 * @create 2021-03-28
 */
@RestController
@RequestMapping("/productCategory")
@Slf4j
public class PmsProductCategoryController {

    @Autowired
    private PmsProductCategoryService categoryService;

    @GetMapping(value = "/list/{parentId}")
    CommonResult<PageResponse<PmsProductCategory>>
    listInParent(@PathVariable("parentId") Long parentId,
                 @RequestParam(value = "pageNum", required = false) Integer pageNum,
                 @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return CommonResult.success(categoryService.list(parentId, pageSize, pageNum));
    }

    @GetMapping(value = "/listAll/{parentId}")
    CommonResult<List<PmsProductCategory>> listAll(@PathVariable("parentId") Long parentId) {
        return CommonResult.success(categoryService.list(parentId));
    }

    @PostMapping(value = "/create")
    CommonResult<Integer> create(@RequestBody PmsProductCategoryParam categoryParam){
        return CommonResult.success(categoryService.create(categoryParam));
    }

    @PostMapping(value = "/delete")
    CommonResult<Integer> delete(@RequestParam(value = "ids") List<Long> ids) {
        return CommonResult.success(categoryService.delete(ids));
    }

    @GetMapping(value = "{id}")
    CommonResult<PmsProductCategoryEntityParam> getItem(@PathVariable("id") Long id) {
        return CommonResult.success(categoryService.getCategory(id));
    }

    @PostMapping(value = "/update/{id}")
    CommonResult<Integer> update(@PathVariable("id")Long id, @RequestBody PmsProductCategoryParam param) {
        return CommonResult.success(categoryService.update(id, param));
    }

    @PostMapping(value = "update/navStatus")
    CommonResult<Integer> updateNavStatus(@RequestParam(value = "ids") List<Long> ids,
                                          @RequestParam(value = "navStatus") Integer status) {
        return CommonResult.success(categoryService.updateNavStatus(ids, status));
    }

    @PostMapping(value = "update/showStatus")
    CommonResult<Integer> updateShowStatus(@RequestParam(value = "ids") List<Long> ids,
                                          @RequestParam(value = "showStatus") Integer status) {
        return CommonResult.success(categoryService.updateShowStatus(ids, status));
    }


}
